const accessToken = uni.getStorageSync('accessToken') || '';
const userinfo = uni.getStorageSync('userinfo') || undefined;

const state = {
    accessToken,
    userinfo,
    tmpUserinfo: {},
}


const getters = {
    hasLogin: state => !!state.accessToken,
    hasUserinfo: state => !!state.userinfo,
    getAccessToken: state => state.accessToken,
    getUserinfo: state => state.userinfo,
    getTmpUserinfo: state => state.tmpUserinfo,
}


const actions = {}

const mutations = {
    setAccessToken: (state, accessToken) => {
        state.accessToken = accessToken
        uni.setStorageSync('accessToken', accessToken);
        console.log("store", "mutations", "setAccessToken", state.accessToken)
    },
    setUserinfo: (state, userinfo) => {
        state.userinfo = userinfo
        uni.setStorageSync('userinfo', userinfo);
        console.log("store", "mutations", "setUserinfo", state.userinfo)
    },
    setTmpUserinfo: (state, tmpUserinfo) => {
        state.tmpUserinfo = tmpUserinfo
        uni.setStorageSync('tmpUserinfo', tmpUserinfo);
        console.log("store", "mutations", "setTmpUserinfo", state.tmpUserinfo)
    },

}


export default {
    namespaced: true,
    state,
    getters,
    actions,
    mutations
}
